import json
import requests
from nturl2path import url2pathname

from loguru import logger

from basic.base import  BaseRequest
from config import ENV


class URL:
    MEMBER_LIST="adminapi/member/member"
    MEMBER_ADD="adminapi/member/member"
    MEMBER_MODIFY="adminapi/member/member/modify"
    MEMBER_MESSAGE="adminapi/member/member"
    MEMBER_LABEL_LIST="adminapi/member/label"
    MEMBER_LABEL_ADD="adminapi/member/label"
    MEMBER_LABEL_MODIFY="adminapi/member/label"

class Member(BaseRequest,URL):

    def member_list(self,keyword=None,register_type=None,member_label=None,register_channel=None,member_level=None,**kwargs):
        """"会员列表，支持条件查询"""
        data = {
                'page' : '1',
                'limit' : '10',
                'keyword' :keyword,
                'register_type' :register_type,
                'member_label':member_label,
                'register_channel' :register_channel,
                'member_level':member_level,
                **kwargs
        }
        return self._get(api_name=self.member_list.__name___,url=self.MEMBER_LIST, params=data)

    def member_add(self,nickname,member_no  ,mobile ,password ,**kwargs):#添加会员
        """添加会员"""
        data = {
            "nickname": nickname,
            "member_no": member_no,
            "mobile": mobile,
            "password": password,
            "password_copy": password,
            **kwargs
            }
        return self._post(api_name=self.member_add.__name___,url=self.MEMBER_ADD,data=data)

    def member_modify(self,member_id,modify,value):
        """"会员编辑"""
        M_URL=self.MEMBER_MODIFY+f"/{member_id}/{modify}"
        data={
            "member_id":member_id,
            "filed":modify,
            "value":value
        }
        return self._put(api_name=self.member_modify.__name___,url=M_URL, data=data)

    def member_message(self,member_id):
        """"会员信息"""
        M_URL=self.MEMBER_MESSAGE+f"/{member_id}"
        return self._get(api_name=self.member_message.__name___,url=M_URL)

    def member_label_list(self,label_name):
        """"标签列表"""
        data = {'page' : '1', 'limit' : '10', 'label_name' : label_name}
        return self._get(api_name=self.member_label_list.__name___,url=self.MEMBER_LABEL_LIST,params=data)
    def member_label_delete(self):
        """"标签删除"""
        pass
    def member_label_add(self,name,**kwargs):
        """"标签添加"""
        url = "http://124.70.39.201/adminapi/member/label"
        data = {
            "label_id" : "",
            "label_name" : name,
            **kwargs
        }
        return  self._post(api_name=self.member_label_add.__name___,url=self.MEMBER_LABEL_ADD,data=data)
    def member_level_list(self):
        """"标签会员等级列表"""
        pass
    def member_level_add(self):
        """"标签添加会员等级"""
        pass
    def member_config_growth_rule(self):
        """"成长值规则"""
        pass
    def member_label_modify(self,label_id,label_name,intro,sort):
        """"标签编辑"""
        data = {
            'method' : 'put',
            'url' : f'http://124.70.39.201/adminapi/member/label/{label_id}',
            'headers' : {'token' : self.token, 'Content-Type' : 'application/json'},
            'json' : {'label_id' : label_id, 'label_name' : label_name, 'memo' : intro, 'sort' : sort}
        }
        response = requests.request(**data)
        return self._put(api_name=self.member_label_modify.__name___,url=response.url,data=data)
    def member_account_balance(self):
        """"账户余额"""
        pass
    def member_account_commission(self):
        """"账户佣金"""
        pass


if __name__ == '__main__':
    member=Member()
    member.member_message(215)
    # print(json.dumps(member.member_list(member_level=1),indent=2,ensure_ascii=False))
